package net.wds.study.student.controller;

import net.sf.json.JSONObject;
import net.wds.study.student.entity.Student;
import net.wds.study.student.modal.PageModal;
import net.wds.study.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by sidongliang on 2020/8/21.
 */
@Controller
@RequestMapping(value="/stu")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @RequestMapping(value = "/getPage",method={RequestMethod.POST})
    //获取前端相应名称属性的value
    private void getPage(@RequestParam Integer startIndex,
                           @RequestParam Integer pageSize,
                           @RequestParam String name,
                           @RequestParam Integer sex,
                           HttpServletResponse response){
        PageModal<Student> resultList = studentService.getPageByParam(startIndex,pageSize,name,sex);
        try {
            //将查询到的list集合转换为JSON类型传回前端
            response.getWriter().write(JSONObject.fromObject(resultList).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }



}
